var Req = {
    timer: 0,

    login: function(obj, nickname) {    //登陆
        obj.send(ErrorCode.SUCCESS, Command.SYS_LOGIN, {nickname: nickname})
    },
    logout: function(obj) { //退出
        obj.send(ErrorCode.SUCCESS, Command.SYS_LOGOUT, {})
    },
    heart: function(obj) {  //心跳
        this.timer = setInterval(function(){
            if (obj.ws.readyState == obj.ws.OPEN) {
                var data = {
                    time: (new Date()).valueOf(),
                }
                obj.send(ErrorCode.SUCCESS, Command.SYS_HEART_REQ, data)
            } else {
                clearInterval(this.timer)
            }
        }, 600000)
    },
    /*searchRoom: function(obj) { //找房间
        obj.send(ErrorCode.SUCCESS, Command.SYS_SEARCH_ROOM, {});
    },*/
    reconnect: function(obj) {
        obj.send(ErrorCode.SUCCESS, Command.SYS_RE_CONNECT_REQ, {});
    },
    start: function(obj) {  //开始游戏
        obj.send(ErrorCode.SUCCESS, Command.GAME_START_REQ, {});
    },
    call: function(obj, call) {    //叫地主或跳过
        obj.send(ErrorCode.SUCCESS, Command.GAME_CALL_REQ, {call: call});
    },
    out: function(obj, cards) { //出牌,cards为空数组即为跳过
        obj.log('out cards')
        obj.log(cards)
        if (Poker.canOut(cards, obj.outs)) {
            obj.send(ErrorCode.SUCCESS, Command.GAME_OUT_REQ, {cards: cards});
        } else {
            alert('未按规则出牌')
        }
    },
    chat: function(obj, content) {
        $('#chat-message-panel').append('<div>我:'+ content +'</div>')
        obj.send(ErrorCode.SUCCESS, Command.CHAT_MSG_REQ, {content: content})
    }
}